******************************************************************************************************
*************************************Replication code for*********************************************
**********The Structure of Religion, Ethnicity & Insurgent Mobilization: Evidence from India**********
*******************************************World Politics*********************************************
**************************************Author: Anoop K. Sarbahi****************************************
*************************************Created: November 13, 2020***************************************
******************************************************************************************************
clear
use SarbahiReplicationData.dta, clear
set more off 
*******************************************************

global y1 prallrec
global y11 prrand
global xkalt mautakprop5km wwiiprop 					/* key alternative */
global xecon windex nonagrp cropplant 					/* economic controls */
global xgeog lnelev5k distroad distnv distborder 		/* geog controls */
global xstat distarps distpo 		 					/* state controls */
global f1 subdist1-subdist28 							/* block fixed effects */

*****************************Table 2: Regression Estimates of Rebel Recruitment: Bivariate Estimates: Bivariate Estimates*****************************

foreach x of varlist pryma ymadum church chXym revdist relymachrev mautakprop5k wwiiprop {  
eststo: qui glm prallrec `x' splag6k $f1, family(binomial) link(logit) cluster(sub_id)
glmcorr
}
esttab using Table2.tex, b(a3) se(a3) label booktabs replace starlevels(** 0.05 *** 0.01)  scalars(aic bic)
eststo clear

*****************************Table 3: Regression Estimates of Rebel Recruitment: Multivariate Estimates*****************************

 foreach x of varlist pryma ymadum church chXym revdist relymachrev {
 eststo: glm $y1 `x' $xkalt $xecon prlit per100 $xgeog $xstat $f1 splag6k, family(binomial) link(logit) cluster(sub_id)
 glmcorr
  }

*****************************Sample restricted to North Lushai Hills (Model 7)*****************************

 eststo: qui glm $y1 pryma $xkalt $xecon prlit per100 $xgeog $xstat  $f1 splag6k if divid==1000, family(binomial) link(logit) cluster(sub_id)
 glmcorr
 
 *****************************Effect of Religiosity (Model 8)*****************************
 
 eststo: qui glm $y1 pryma titheperpop $xkalt $xecon prlit per100 $xgeog $xstat  $f1 splag6k, family(binomial) link(logit) cluster(sub_id)
 glmcorr
 esttab using Table3.tex, b(3) se(3) scalars(r2 aic bic) label booktabs replace starlevels(** 0.05 *** 0.01)
 eststo clear
 
*****************************Table 4: Selection on Unobserved Variables Relative to Observed Variables*****************************

qui glm $y1 pryma $f1 splag6k, family(binomial) link(logit) cluster(sub_id)
glmcorr
gen b1=_b[pryma]
qui glm $y1 pryma $xkalt  $f1 splag6k, family(binomial) link(logit) cluster(sub_id)
glmcorr
gen b2=_b[pryma]
qui glm $y1 pryma $xkalt $xecon prlit $f1 splag6k, family(binomial) link(logit) cluster(sub_id)
glmcorr
gen b3=_b[pryma]
qui glm $y1 pryma $xkalt $xecon prlit per100 $f1 splag6k, family(binomial) link(logit) cluster(sub_id)
glmcorr
gen b4=_b[pryma]
qui glm $y1 pryma $xkalt $xecon prlit per100 $xgeog $f1 splag6k, family(binomial) link(logit) cluster(sub_id)
glmcorr
gen b5=_b[pryma]
qui glm $y1 pryma $xkalt $xecon prlit per100 $xgeog $xstat  $f1 splag6k, family(binomial) link(logit) cluster(sub_id)
glmcorr
gen bF=_b[pryma]

                                                        .
forvalues i = 1(1)5{
g ratio`i'=bF/(b`i'-bF)
}

drop b1-ratio5

save SarbahiReplicationData.dta, replace

***************************************************************************************************
*****************************Tables included in Supplementary Material*****************************
***************************************************************************************************

*****************************Table A-1: Summary Statistics*****************************
 estpost sum prallrec pryma ymadum church chXym revdist relymachrev mautakprop5km wwiiprop per100  windex nonagrp cropp prlit cropp lnelev5k distroad distnv  distborder distarps distpo, listwise
 esttab using TableA1.tex, cells("mean(fmt(3)) sd(fmt(3)) min(fmt(3)) max (fmt(3))") label nomtitle nonumber

*****************************Table A-2: Correlation Matrix*****************************
 estpost cor pryma ymadum church chXym revdist relymachrev mautakprop5km wwiiprop per100  windex nonagrp cropp prlit cropp lnelev5k distroad distnv  distborder distarps distpo, matrix listwise
 esttab using TableA2.tex, cells(b(fmt(3))) label unstack not nostar noobs nonum nomti compress
 
*****************************Table A3: Bivariate Estimates*****************************

foreach x of varlist pryma ymadum church chXym revdist relymachrev mautakprop5km wwiiprop per100 windex nonagrp cropp prlit lnelev5k distroad distnv  distborder distarps distpo {  
eststo: qui glm prallrec `x' splag6k $f1, family(binomial) link(logit) cluster(sub_id)
glmcorr
}
esttab using TableA3.tex, b(a3) se(a3) label booktabs replace starlevels(** 0.05 *** 0.01)  scalars(aic bic)

eststo clear


*****************************NOTE THAT TABLE A-4 IS THE SAME AS TABLE 3 WITH THE ESTIMATES OF CONTROL VARIABLES EXCLUDED*****************************  

*****************************Table A-5: Sample Restricted to North Lushai Hills*****************************

foreach x of varlist pryma  ymadum chXym revdist relymachrev {

eststo: qui glm $y1 `x' $xkalt $xecon prlit per100 $xgeog $xstat $f1 splag6k  if divid==1000, family(binomial) link(logit) cluster(sub_id)
glmcorr
}

esttab using TableA5.tex, b(3) se(3) scalars(r2 aic bic) label booktabs replace starlevels(* 0.10 ** 0.05 *** 0.01)
eststo clear


*****************************Table A-6: OLS & GLM Estimates Compared*****************************

foreach x of varlist pryma  ymadum chXym revdist relymachrev {
eststo: qui glm $y1 `x' $xkalt $xecon prlit per100 $xgeog $xstat  $f1 splag6k, family(binomial) link(logit) cluster(sub_id)
glmcorr
}

foreach x of varlist pryma  ymadum chXym revdist relymachrev {
eststo: qui regress $y1 `x' $xkalt $xecon prlit per100 $xgeog $xstat  $f1 splag6k, cluster(sub_id)
}

esttab using TableA6.tex, b(3) se(3) scalars(aic bic) label booktabs replace starlevels(* 0.10 ** 0.05 *** 0.01)
eststo clear

*****************************Table A-7: Varying Radii for the Spatial Lag*****************************

eststo: glm $y1 pryma $xkalt $xecon prlit per100 $xgeog $xstat  $f1 splag6k, family(binomial) link(logit) cluster(sub_id)
forvalues r=10(5)25 {
eststo: glm $y1 pryma $xkalt $xecon prlit per100 $xgeog $xstat  $f1 splag`r'k, family(binomial) link(logit) cluster(sub_id)
glmcorr
}
esttab using TableA7.tex, b(3) se(3) scalars(aic bic) label booktabs replace starlevels(** 0.05 *** 0.01)
eststo clear
 
*****************************Table A-8: Recruits with Missing Location Assigned to Villages With High Deviance Residuals*****************************

foreach x of varlist pryma chXym revdist relymachrev {
 eststo: glm $y1 `x' $xkalt $xecon prlit per100 $xgeog $xstat  $f1 splag6k, family(binomial) link(logit) cluster(sub_id)
 glmcorr
  }
foreach x of varlist pryma chXym revdist relymachrev {
 eststo: qui glm $y11 `x' $xkalt $xecon prlit per100 $xgeog $xstat  $f1 splag6k, family(binomial) link(logit) cluster(sub_id)
 glmcorr
  }
esttab using TableA8.tex, b(3) se(3) scalars(aic bic) label booktabs replace starlevels(** 0.05 *** 0.01)
eststo clear
 

*****************************Table A-9: Measures of Geographical Proximity as Control Variables*****************************

set more off
foreach x of varlist numneigh lnvill distnv { 
eststo: qui glm $y1 pryma $xkalt $xecon prlit per100 lnelev5k distroad distborder $xstat `x'  $f1 splag6k, family(binomial) link(logit) cluster(sub_id)
glmcorr
}
esttab using TableA9.tex, b(3) se(3) scalars(aic bic) label booktabs replace starlevels( ** 0.05 *** 0.01)
eststo clear


*****************************Table A-10: Subsets of Recruits as Dependent Variable*****************************

set more off
foreach y of varlist prallrec surprop arrestprop retprop propretarrsur {
eststo: qui glm `y' pryma $xkalt $xecon prlit per100 $xgeog $xstat  $f1 splag6k, family(binomial) link(logit) cluster(sub_id)
glmcorr
}
esttab using TableA10.tex, b(3) se(3) scalars(aic bic) label booktabs replace starlevels(** 0.05 *** 0.01)
eststo clear
	
	
/* 
***********************************This section is purposefully commented out*********************************** 
******************The code below can be used to generate the two indices used in the article********************
  
*****************************Principal Component Analysis (PCA) to Create the Village Prosperity Index (windex)*****************************
pca commdev-weeklyb

*****************************Generate predicted values of two components based on PCA*****************************
predict w1 w2

*****************************Returned values re-scaled to fall between 0-100*****************************
foreach v of varlist w1 w2 {
    summarize `v', meanonly
    gen `v'_100 = 100*(`v'-`r(min)')/(`r(max)'-`r(min)')
}

*****************************Generate Village Prosperity Index by combining the two components***************************** 
g w11=(w1_100+w2_100)/100


*****************************Principal Component Analysis (PCA) to Create Stuctural Connectivity Index (relymachrev)*************************

pca pryma revdist church
predict relymachrev


*/



